//
//  CollectionHeaderView.m
//  atlas
//
//  Created by 你好 on 16/12/29.
//  Copyright © 2016年 xyxNav. All rights reserved.
//

#import "CollectionHeaderView.h"
#import "PGIndexBannerSubiew.h"
#import "UserManager.h"
@interface CollectionHeaderView ()

///<NewPagedFlowViewDelegate,NewPagedFlowViewDataSource>


@end

@implementation CollectionHeaderView


-(instancetype)initWithFrame:(CGRect)frame
{
    self=[super initWithFrame:frame];
    if (self)
    {
        [self configUI];
    }
    return self;
}

-(void)prepareForReuse
{
    [super prepareForReuse];
//    self.pageFlowView.frame=CGRectMake(0, 0, self.bounds.size.width, self.bounds.size.height);
//    self.pageFlowView.scrollView.frame=self.pageFlowView.bounds;
//    self.pageFlowView.superViewOfScrollView.frame=self.pageFlowView.bounds;
//    [self.pageFlowView layoutSubviews];
//    [self.pageFlowView reloadData];
}

-(void)configUI
{
//    self.backgroundColor=[UIColor colorWithWhite:1 alpha:0.5];
    
//    self.imageArray=[[NSMutableArray alloc]initWithCapacity:0];
//    for (int i=1; i<=5; i++)
//    {
//        if (i%3==0)
//        {
//            [self.imageArray addObject:[UIImage imageNamed:@"3.jpg"]];
//        }
//        else
//        {
//            UIImage *image=[UIImage imageNamed:[NSString stringWithFormat:@"%d.jpg",i%3]];
//            [self.imageArray addObject:image];
//        }
//    }
    
//    self.pageFlowView=[[NewPagedFlowView alloc]initWithFrame:CGRectMake(0, 0, self.bounds.size.width, self.bounds.size.height)];
//    self.pageFlowView.minimumPageAlpha = 0.4;
//    self.pageFlowView.minimumPageScale = 0.85;
//    self.pageFlowView.delegate=self;
//    self.pageFlowView.dataSource=self;
//    self.pageFlowView.orginPageCount = self.imageArray.count;
//    [self addSubview:self.pageFlowView];
    
//    self.pageControl = [[UIPageControl alloc] initWithFrame:CGRectMake(0, self.pageFlowView.bounds.size.height - 24 - 8, self.pageFlowView.bounds.size.width, 8)];
//    self.pageFlowView.pageControl = self.pageControl;
//    [self.pageFlowView addSubview:self.pageControl];
//    [self.pageFlowView reloadData];
    
    self.backImageView=[[UIImageView alloc]init];
    self.backImageView.contentMode=UIViewContentModeScaleAspectFill;
    self.backImageView.clipsToBounds=YES;
    self.backImageView.userInteractionEnabled=YES;
    [self addSubview:self.backImageView];
    
    self.coverViewBtn=[[UIButton alloc]init];
    self.coverViewBtn.backgroundColor=[UIColor colorWithWhite:1 alpha:0.5];
    self.coverViewBtn.userInteractionEnabled=YES;
    [self.backImageView addSubview:self.coverViewBtn];
    
    [self.backImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.top.right.bottom.equalTo(self);
    }];
    
    [self.coverViewBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.top.right.bottom.equalTo(self.backImageView);
    }];

}


-(void)configData:(Recommend *)recommend
{
//    self.imageArray=recommendArray;
//    self.pageFlowView.orginPageCount=self.imageArray.count;
//    [self.pageFlowView reloadData];
    self.coverViewBtn.alpha=0.5f;
    NSString *bgImageUrl=[NSString stringWithFormat:@"%@/%@?token=%@",GETIMAGE_URL,recommend.imageUrl,[UserManager shareInstance].userToken];
    [self.backImageView sd_setImageWithURL:[NSURL URLWithString:bgImageUrl] completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
        [UIView animateWithDuration:1.5 animations:^{
            self.coverViewBtn.alpha=0.02f;
        }completion:^(BOOL finished) {
        }];
    }];

}


//#pragma mark - <NewPagedFlowViewDelegate>
//
//- (CGSize)sizeForPageInFlowView:(NewPagedFlowView *)flowView
//{
//    if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone)
//    {
//        return CGSizeMake(self.bounds.size.width - 84, self.bounds.size.height);
//    }
//    else
//    {
//        return CGSizeMake(self.bounds.size.width - 168, self.bounds.size.height);
//    }
//}
//
//- (void)didSelectCell:(UIView *)subView withSubViewIndex:(NSInteger)subIndex
//{
//    NSMutableDictionary *dict=[NSMutableDictionary dictionary];
//    
//    if (_delegate && [_delegate respondsToSelector:@selector(didSelectedItem:andInfo:)])
//    {
//        [_delegate didSelectedItem:subIndex andInfo:dict];
//    }
//}
//
//#pragma mark - <NewPagedFlowViewDatasource>
//
//- (NSInteger)numberOfPagesInFlowView:(NewPagedFlowView *)flowView
//{
//    return self.imageArray.count;
//}
//
//- (UIView *)flowView:(NewPagedFlowView *)flowView cellForPageAtIndex:(NSInteger)index
//{
//    PGIndexBannerSubiew *bannerView = (PGIndexBannerSubiew *)[flowView dequeueReusableCell];
//    if (!bannerView)
//    {
//        if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone)
//        {
//            bannerView = [[PGIndexBannerSubiew alloc] initWithFrame:CGRectMake(0, 0, self.bounds.size.width - 84, self.bounds.size.height)];
//            bannerView.layer.cornerRadius = 4;
//            bannerView.layer.masksToBounds = YES;
//        }
//        else
//        {
//            bannerView = [[PGIndexBannerSubiew alloc] initWithFrame:CGRectMake(0, 0, self.bounds.size.width - 84, self.bounds.size.height)];
//            bannerView.layer.cornerRadius = 4;
//            bannerView.layer.masksToBounds = YES;
//        }
//    }
//    //在这里下载网络图片
//    Recommend *recommend=[self.imageArray objectAtIndex:index];
//    NSURL *url=[NSURL URLWithString:[NSString stringWithFormat:@"%@/%@?token=%@",GETIMAGE_URL,recommend.imageUrl,[UserManager shareInstance].userToken]];
//    [bannerView.mainImageView sd_setImageWithURL:url placeholderImage:[UIImage imageNamed:@"1.jpg"]];
//    return bannerView;
//}



@end
